<?php
require_once "includes/pagination.php";

if(!empty($_REQUEST['editSellingProduct']))
{
$productId=$_REQUEST['editSellingProduct'];
$ownerId= $_SESSION['user_id_sess'];
$itemPerPage=10;
$productInfo=getProductById($productId);
}
else
  echo "<script type='text/javascript'> window.location='index.php?notFound'; </script>";
  
?>
<div id='panel'>
<table width="100%" border="0">
<tr>
    <td class="contentHeader"><h2>Sellers selling your product</h2></td>
  </tr>
  <tr class='head-tr'>
  <td height="27"><strong><?php echo $productInfo['product_name']; ?></strong></td>
  </tr>
    
  <tr>
    <td><?php
	//delete single product		 
			if(!empty($_REQUEST['hidDelPro'])) {
				$proId=$_REQUEST['hidDelPro'];
				$delType=$_REQUEST['hidDelProKey'];
				if($delType=='prod')
				   $sqlDelPro="Delete from tbl_product where product_id=$proId";
				else if($delType=='item')
				   $sqlDelPro="Delete from tbl_items where item_id = $proId";
				$rstDelPro=mysql_query($sqlDelPro);
				if($rstDelPro) { 
					//$imgPaths=getImagePath($proId);
					//if($imgPaths[0]!="") { unlink($imgPaths[0]); }
					//if($imgPaths[1]!="") { unlink($imgPaths[1]); }
					//if($imgPaths[2]!="") { unlink($imgPaths[2]); }
					echo "<div id='suc-msg'> Your product deleted. </div><br>"; 
				}	
				else {
					echo "<div id='err-msg'> Your product could not be deleted. </div><br>";
				}
			}
		if(isset($_REQUEST['editSellingProductOwnKey'])) {
		$itemId=$_REQUEST['editSellingProductOwnKey'];
		$commission=$_REQUEST['commission'];
		$price=$_REQUEST['price'];
		$sqlSelItemUpd="SELECT * FROM tbl_items where item_id='$itemId'";
		$rstSelItemUpd=mysql_query($sqlSelItemUpd);			
		$rowSelItemUpd=mysql_fetch_array($rstSelItemUpd);	
		$commissionExist=$rowSelItemUpd['commission'];
		$sqlUpdSellingProd="UPDATE tbl_items SET commission='$commission', price='$price', bargained=1 WHERE item_id=$itemId";
		$rstUpdSellingProd=mysql_query($sqlUpdSellingProd);
		$noUpdSellingProd=mysql_affected_rows();
		if($noUpdSellingProd>0){ 			
			echo "<div id='suc-msg'> Your selling Product edited. </div>"; 
		}
		else {
			echo "<div id='err-msg'> Error on editing selling product. </div>";
		}
	}
	
		  		   $sqlSelSellerList="SELECT * FROM tbl_items where owner_id='$userId' and product_id='$productId' ORDER BY item_id DESC";
				   $rstSelSellerList=mysql_query(getPagingQuery($sqlSelSellerList,$itemPerPage));				
				   $noSelSellerList=mysql_num_rows($rstSelSellerList);
				   if($noSelSellerList==0)
				   {
				   	  
					  echo "<div style='border-top:1px solid #CCCCCC;'> </div><br>";
					  echo "<p style='padding:5px;'>No items found on your list...</p><br>";
					  echo "<div style='border-top:1px solid #CCCCCC;'> </div><br>";
					}
				   else {
				   ?>
    <a name="editOwn" id="editOwn"></a><tr><td>
		    <form name="frmProListSellers" id="frmProListSellers" method="post" action="">
		 	<input type="hidden" name="hidDelPro" id="hidDelPro">
            <input type="hidden" name="hidDelProKey" id="hidDelProKey">
            <input type="hidden" name="hidEditSellingItemOwn" id="hidEditSellingItemOwn"> 

				   		  <br><table width='100%' border='0' align='center' cellspacing='0'>
						  <tr class='head-tr'>
								  <td width="5%"><strong>S.No</strong></td>								
								  <td width="25%"><strong>Seller name </strong></td>
								  <td width="23%"><strong>Product name </strong></td>
								  <td width="23%"><strong>commission(PP)</strong></td>
								  <td width="23%"><strong>Price + Shipp ( PP )</strong></td>
								  <td width="24%">&nbsp;</td>
						    </tr>
						 <?php
						 $r=1;
						$pname=$productInfo['product_name'];
						 while($rowSelSellerList=mysql_fetch_array($rstSelSellerList))
					     {				
						    $sellerName=getUser($rowSelSellerList['seller_id']);	   
						    $itemId=$rowSelSellerList['item_id'];
							
							$price=$rowSelSellerList['price'];
							$commission=$rowSelSellerList['commission'];
						   echo "<tr>
						   		 <td height='28'> $r </td>					         
								 <td>$sellerName</td>
								 <td><a href='index.php?SellProduct=$productId'>$pname</a></td>
								 <td>$commission</td>
								 <td>$price</td>
								 <td><a href='javascript:void(0);' onClick=funDelProduct('frmProListSellers','item',$itemId)>Delete</a></td>
							   </tr>";
							echo "<tr>
									 <td colspan='6'> <div style='border-top:1px solid #CCCCCC;'> </div> </td>
								  </tr>";
						 	$r++;
						 } ?>
						</table>				    	
		   <?php
		   } 								
	?>
	</form></td>
</tr>
<tr>
	<td><div align="center"><?php
		   $link="editSellingProduct";
		   echo $disp=getPagingLink($sqlSelSellerList,$itemPerPage,$link);
	 ?></div></td>
</tr>
<tr>
<td>
  <?php
  if(!empty($_REQUEST['hidEditSellingItemOwn'])) {
    $sqlSelLstEdit="SELECT * FROM tbl_items where item_id=".$_REQUEST['hidEditSellingItemOwn'];
    $rstSelLstEdit=mysql_query($sqlSelLstEdit);
	$rowSelLstEdit=mysql_fetch_array($rstSelLstEdit);
	$productInfo=getProductById($rowSelLstEdit['product_id']);
  ?>
   <div id="divEditSellingProductOwn">
    <form name="frmEditSellingProduct" id="frmEditSellingProduct" method="post" action="">
    <input type="hidden" name="editSellingProductOwnKey" id="editSellingProductOwnKey" />
      <table width="100%" border="0">
        <tr  class='head-tr'>
          <td colspan="3"><strong>Edit product</strong></td>
        </tr>
        <tr>
          <td height="29">&nbsp;</td>
          <td><strong>Seller</strong></td>
          <td><?php if(!empty($rowSelLstEdit['seller_id']))
			echo $sellerName=getUser($rowSelLstEdit['seller_id']);
			?></td>
        </tr>
        <tr>
          <td height="29">&nbsp;</td>
          <td width="21%"><strong>Price</strong></td>
          <td width="77%"><input type="text" name="price" id="price" size="33" value="<?php if(!empty($rowSelLstEdit['price']))
			echo $rowSelLstEdit['price'];
			?>"/></td>
        </tr>
        <tr>
          <td height="31">&nbsp;</td>
          <td><strong>Comission (PP)</strong></td>
          <td><input type="text" name="commission" id="commission" size="33" value="<?php if(!empty($rowSelLstEdit['commission']))
			echo $rowSelLstEdit['commission'];
			?>"/></td>
        </tr>
        <tr>
          <td height="34">&nbsp;</td>
          <td>&nbsp;</td>
          <td><label>
            <input type="button" name="editSellingProduct" id="editSellingProduct" value="Edit product" onclick="funEditSellingProductOwn('frmEditSellingProduct',<?php  if(!empty($_REQUEST['hidEditSellingItemOwn'])) echo $_REQUEST['hidEditSellingItemOwn'];?>)" />
          </label></td>
        </tr>
      </table>
      </form>
    </div>
    <?php } ?>    </td>
    </tr>
    </table>
</div>